package com.wu.rabbitmq.two;

import com.rabbitmq.client.Channel;
import com.wu.rabbitmq.utils.RabbitMQUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @program: RabbitMQ-Study
 * @author: 吴磊
 * @create: 2021-12-13 14:04
 * 生产者，可以发送大量的消息
 */
public class Task01 {

    private static String QUEUE_NAME = "hello";

    //准备发送大量的消息
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取通道
        Channel channel = RabbitMQUtils.getChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //从控制台中接受消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("消息发送完毕：" + message);
        }

    }

}
